package com.xbk.seckill.application.dubbo;

import com.xbk.seckill.application.service.SeckillGoodsService;
import com.xbk.seckill.common.cache.distribute.DistributedCacheService;
import com.xbk.seckill.common.cache.model.SeckillBusinessCache;
import com.xbk.seckill.common.model.dto.SeckillGoodsDTO;
import com.xbk.seckill.dubbo.interfaces.goods.SeckillGoodsDubboService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 商品Dubbo服务实现类
 *
 * @author xiexu
 * @date 2025/2/10 22:51
 */
@Slf4j
@Component
@DubboService(version = "1.0.0")
public class SeckillGoodsDubboServiceImpl implements SeckillGoodsDubboService {

    @Autowired
    private SeckillGoodsService seckillGoodsService;

    @Autowired
    private DistributedCacheService distributedCacheService;

    /**
     * 根据id和版本号获取商品详情
     *
     * @param id
     * @param version
     * @return
     */
    @Override
    public SeckillGoodsDTO getSeckillGoods(Long id, Long version) {
        return seckillGoodsService.getSeckillGoods(id, version);
    }

    @Override
    public boolean updateDbAvailableStock(Integer count, Long id) {
        return seckillGoodsService.updateDbAvailableStock(count, id);
    }

    @Override
    public boolean updateAvailableStock(Integer count, Long id) {
        return seckillGoodsService.updateAvailableStock(count, id);
    }

    @Override
    public Integer getAvailableStockById(Long goodsId) {
        return seckillGoodsService.getAvailableStockById(goodsId);
    }

    /**
     * 获取商品的可用库存
     *
     * @param goodsId
     * @param version
     * @return
     */
    @Override
    public SeckillBusinessCache<Integer> getAvailableStock(Long goodsId, Long version) {
        log.info("调用商品Dubbo服务");
        return seckillGoodsService.getAvailableStock(goodsId, version);
    }
}
